<?php
class Delivery_Model_Logger
{
	public function logAction( Zend_Controller_Request_Http $request, Delivery_Model_Administrador $user)
	{
		
		$ob = new stdClass();
		$ob->controller	= $request->getControllerName();
		$ob->action		= $request->getActionName();
		$ob->ip			= $request->getClientIp();
		$ob->params		= $request->getParams();
		$ob->userId		= $user->idAdministrador;	

		unset($this->params['controller']); 
		unset($this->params['action']); 
		unset($this->params['module']); 
		
		$dbTable1 = Delivery_Model_Factory::dbTable('ActionsLog');
		$ob->idLog = $dbTable1->insert( $ob );
		
		$dbTable1 = Delivery_Model_Factory::dbTable('ActionsLogParams');
		$dbTable1->multiInsert( $ob );
		
		
	}
	
	public function logDeleted( Delivery_Model_Abstract $object )
	{
		$className	= get_class($object);
		
		$vars = array_intersect_key(
			get_object_vars( $object ), 
			get_class_vars( $className )
		);

		$dbTable1 = Delivery_Model_Factory::dbTable('DeletedLog');
		$idLog = $dbTable1->insert( $className );
		
		$dbTable1 = Delivery_Model_Factory::dbTable('DeletedLogVars');
		$dbTable1->multiInsert( $vars, $idLog );				
	}
	
	public function logSearch( $what, $where, $ip, $resultados)
	{
		$what = substr($what, 0,254);
		$where = substr($where, 0,254);
		
		$dbTable1 = Delivery_Model_Factory::dbTable('SearchLog');
		$dbTable1->insert( $what, $where, $ip, $resultados );
	}
	
		
	
}
